<template>
	<view>
		<view style="font-size:28rpx;line-height:20px;color: #999;padding:20px;">提示：</br>触发条件：每次触发升级奖励时，概率获得限时分红猫。需要有移动 、合并等操作的时候才会计算收益。若玩家新合成的猫的等级超过历史最高等级时触发，根据对应条件获得对应奖品，例如现在最高级6，合成两个6级有机会获得，但是合成5级就没有。</br>升级奖励：获得设置分钟上限和下限区间内的限时分红猫。</br>限时分红猫收益：根据当日永久分红猫收益，与随机限时时长（上限分钟数~下限分钟数）所占全天的比例得出。</view>
		<view class="uni-container" style="float: left;">
			<uni-forms ref="form" validateTrigger="bind">
				<uni-forms-item label="升级获得限时分红猫概率(百分比)" name="title" labelWidth="250">
					<input class="uni-input-border" type="number" v-model="xianshicat.gailv" />
				</uni-forms-item>
				<uni-forms-item label="限时分红猫时长下限(分钟)" name="title" labelWidth="250">
					<input class="uni-input-border" type="number" v-model="xianshicat.time1" />
				</uni-forms-item>
				<uni-forms-item label="限时分红猫时长上限(分钟)" name="title" labelWidth="250">
					<input class="uni-input-border" type="number" v-model="xianshicat.time2" />
				</uni-forms-item>
				<view class="uni-button-group pointer">
					<button class="uni-button uni-button-full" type="primary" :disabled="isLoading" @click="save">保存</button>
				</view>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLoading:false,
				"xianshicat":{
					"gailv":0,
					time1:0,
					time2:0
				}
			}
		},
		mounted() {
			this.getinfo()
		},
		methods: {
			getinfo(){
				this.isLoading = true
				uni.showLoading({
					title: '加载中'
				});
				uniCloud.callFunction({
					name: 'uni-admin',
					data: {
						action: "admin/loadconfig",
						data: {
							id: 'xianshicat'
						}
					}
				}).then((res) => {
					console.log(res, "get--------------")
					this.isLoading = false
					this.xianshicat = res.result.config
					uni.hideLoading();
				}).catch((res) => {
					console.log(res)
				}).finally(err => {
					this.isLoading = false
					uni.hideLoading();
				})
			},
			save(){
				this.isLoading = true
				delete this.xianshicat._id;
				for(let key in this.xianshicat){
					if(key != '_id'){
						this.xianshicat[key] = Number(this.xianshicat[key])
					}
				}
				console.log(this.xianshicat)
				uni.showLoading({
					title: '保存中'
				});
				uniCloud.callFunction({
					name: 'uni-admin',
					data: {
						action: "admin/setconfig",
						data: {
							json: JSON.stringify({
								xianshicat: this.xianshicat
							})
						}
					}
				}).then((res) => {
					console.log(res, "res--------------")
					this.isLoading = false
					uni.hideLoading();
					uni.showToast({
						title: "修改成功",
						icon: 'none',
						duration: 2000
					})
				}).catch((res) => {
					console.log(res)
				}).finally(err => {
					this.isLoading = false
					uni.hideLoading();
				})
			}
		}
	}
</script>

<style>

</style>
